<template>
  <div class="stockFreezing">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">库存转移</span>
        <el-button style="float: right;" type="primary" @click="dialogOpen('add')">新增</el-button>
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-form-item slot="multiSelect" label="多选操作" prop="multiSelect" v-if="table.multiSelect">
          <el-row>
            <el-col :span="8">
              <el-button size="small" type="danger" @click="tableDelete('')">多选删除</el-button>
            </el-col>
            <el-col :span="8">
              <el-button size="small"  type="info" @click="tableConfirm('')">确认收货</el-button>
            </el-col>
            <el-col :span="8">
              <el-button size="small" type="info" @click="tableExport('')">多选导出</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="创建人" prop="cjry">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_cjry"
                    placeholder="创建人" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="提起人" prop="tqrxm">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_tqrxm"
                    placeholder="提起人" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" prop="cjsj">
          <el-date-picker
            v-model="autoVue_table_cjsj"
            type="daterange"
            placeholder="选择日期范围">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="移动状态" prop="ydzt">
          <el-select v-model="autoVue_table_ydzt"
                     placeholder="移动状态">
            <el-option
              label="全部"
              value=""></el-option>
            <el-option
              v-for="item in STOCKTRANSFER.ydzt"
              :key="item.dictionaryid"
              :label="item.value"
              :value="item.dictionaryid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="可用操作"
          width="120">
          <template slot-scope="s">
            <el-button type="info" size="mini" icon="search" @click="dialogSearchOpen(s.row)"></el-button>
            <el-button type="info"  size="mini" @click="tableExport(s.row)">导出</el-button>
            <el-tooltip placement="top" v-if="s.row.ydzt === '0'">
              <div slot="content">更多可用操作</div>
              <el-popover
                popper-class="demo-table-expand"
                placement="right"
                title="更多可用操作"
                trigger="click">
                <slot name="content">
                  <el-button type="info" size="mini" icon="edit" @click="tableEdit(s.row)"></el-button>
                  <el-button type="info" size="mini" @click="tableConfirm(s.row)">确认</el-button>
                  <el-button type="danger" icon="delete" size="mini" @click="tableDelete(s.row)"></el-button>
                </slot>
                <el-button slot="reference" type="info" icon="more" :plain="true" size="mini" class="__reference"></el-button>
              </el-popover>
            </el-tooltip>
          </template>
        </el-table-column>
      </s-table>
    </el-card>
    <s-dialog :dialog="dialog" :close="dialogInit">
      <p slot="title">{{dialog.title}}库存移动</p>
      <s-form :form="formDialog" ref="formDialog">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="tqrxm" label="提起人">
              <el-input
                type="text"
                v-model="formDialog.tqrxm"
                placeholder="提起人"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="ydyy" label="移动原因">
              <el-input
                type="text"
                v-model="formDialog.ydyy"
                placeholder="移动原因"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" v-if="false">
            <el-form-item label="用户名">
              <div class="s-content">
                <el-tag type="success">{{USER.user.name}}</el-tag>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <div class="__table" v-if="this.dialog.title === '新增'">
        <el-button @click="dialogAddMxOpen('add')" class="__table_button"><i class="el-icon-plus"></i></el-button>
      </div>
      <s-table
        :table="tableAdd" ref="tableAdd" @http="tableWatch" :control="false" v-if="this.dialog.title === '新增'">
        <!--
        <el-form-item label="地址" prop="khdz">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_tableAdd_khdz"
                    placeholder="地址" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="联系人" prop="lxrxm">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_tableAdd_lxrxm"
                    placeholder="联系人" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="波次编号" prop="bcbh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_tableAdd_bcbh"
                    placeholder="波次编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="客户名称" prop="khmc">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_tableAdd_khmc"
                    placeholder="客户名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="发运单号" prop="fybh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_tableAdd_fybh"
                    placeholder="发运单号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        -->
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="可用操作"
          width="120">
          <template slot-scope="s">
            <el-button type="info" size="mini" icon="edit" @click="dialogAddEditOpen(s.row)"></el-button>
            <el-button type="danger" icon="delete" size="mini" @click="tableAddDelete(s.$index)"></el-button>
          </template>
        </el-table-column>
      </s-table>
      <el-button slot="footer" type="success"  @click="dialogSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogAddMx" :close="dialogAddMxInit">
      <p slot="title">{{dialogAddMx.title}}库存移动明细</p>
      <s-table :table="tableAddMx" ref="tableAddMx" @http="tableWatch" :multiSelect="true" >
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="操作"
          width="80">
          <template slot-scope="s">
            <el-button type="info" size="mini" @click="dialogLocationOpen(s.row)">选择</el-button>
          </template>
        </el-table-column>
        <el-form-item label="货品编号" prop="hpbh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_tableAddMx_hpbh"
                    placeholder="货品编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="货品名称" prop="hpmc">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_tableAddMx_hpmc"
                    placeholder="货品名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="货品批次" prop="hpph">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_tableAddMx_hpph"
                    placeholder="货品批次" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <!--<el-form-item label="库位名称" prop="show_kwid">-->
          <!--<el-input type="text"-->
                    <!--class="input"-->
                    <!--v-model="autoVue_tableAddMx_show_kwid"-->
                    <!--placeholder="库位名称" spellcheck="false" auto-capitalize="off" auto-complete="off"-->
                    <!--auto-correct="off"></el-input>-->
        <!--</el-form-item>-->
        <el-form-item label="生产日期" prop="hpscrq">
          <el-date-picker
            v-model="autoVue_tableAddMx_hpscrq"
            type="daterange"
            placeholder="选择日期范围">
          </el-date-picker>
        </el-form-item>
      </s-table>
      <el-button slot="footer" @click="dialogAddMxSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogLocation" :close="dialogLocationInit">
      <p slot="title">{{dialogLocation.title}}目标储位</p>
      <s-form :form="formDialogLocation" ref="formDialogLocation">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="ydhkwid" label="目标储位">
              <el-select v-model="formDialogLocation.ydhkwid"
                         ref="formDialogLocation_ydhkwid"
                         filterable
                         remote
                         @change="dialogRemoteKwid"
                         placeholder="请选择种目标储位"
                         :remote-method="dialogRemoteKwmc">
                <el-option
                  v-for="item in dialogLocation.wmsstockmove"
                  :key="item.ydhkwid"
                  :label="item.show_ydhkwid"
                  :value="item.ydhkwid">
                </el-option>
              </el-select>
            </el-form-item>
            <!--
            <el-form-item prop="ydhkwid" label="目标储位">
              <el-select v-model="formDialogLocation.ydhkwid"
                         ref="formDialogLocation_ydhkwid"
                         filterable
                         placeholder="请选择目标储位">
                <el-option
                  v-for="item in dialogLocation.wmsstockmove"
                  :key="item.ydhkwid"
                  :label="item.show_ydhkwid"
                  :value="item.ydhkwid">
                </el-option>
              </el-select>
            </el-form-item>
            -->
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogLocationSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogAddEdit" :close="dialogAddEditInit">
      <p slot="title">{{dialogAddEdit.title}}明细</p>
      <s-form :form="formDialogAddEdit" ref="formDialogAddEdit">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="hpbh" label="货品编号">
              <el-input
                type="text"
                disabled
                v-model="formDialogAddEdit.hpbh"
                placeholder="货品编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="hpmc" label="货品名称">
              <el-input
                type="text"
                disabled
                v-model="formDialogAddEdit.hpmc"
                placeholder="货品编号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="dwms" label="单位描述">
              <el-input
                type="text"
                disabled
                v-model="formDialogAddEdit.dwms"
                placeholder="单位描述"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="hpph" label="货品批次">
              <el-input
                type="text"
                disabled
                v-model="formDialogAddEdit.hpph"
                placeholder="货品批次"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="hpscrq" label="生产日期">
              <el-input
                type="text"
                disabled
                v-model="formDialogAddEdit.hpscrq"
                placeholder="生产日期"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="show_kwid" label="移动前库位">
              <el-input
                type="text"
                disabled
                v-model="formDialogAddEdit.show_kwid"
                placeholder="移动前库位"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="kydsl" label="可移动数量">
              <el-input
                type="text"
                disabled
                v-model="formDialogAddEdit.kydsl"
                placeholder="可移动数量"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="show_ydhkwid" label="目标储位">
              <el-select v-model="formDialogAddEdit.show_ydhkwid"
                         ref="formDialogAddEdit_ydhkwid"
                         filterable
                         placeholder="请选择目标储位">
                <el-option
                  v-for="item in dialogLocation.wmsstockmove"
                  :key="item.ydhkwid"
                  :label="item.show_ydhkwid"
                  :value="item.ydhkwid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="zysl" label="移动数量">
              <el-input-number
                :min="0" :max="parseInt(formDialogAddEdit.kydsl)"
                v-model="formDialogAddEdit.zysl"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogAddEditSave">保存</el-button>

    </s-dialog>
    <s-dialog :dialog="dialogSearch" :close="dialogSearchInit">
      <p slot="title">{{dialogSearch.title}}明细</p>
      <div class="__table">
        <el-button @click="dialogSearchMxOpen('add')" class="__table_button" v-if="dialogSearch.row.ydzt === '0'"><i class="el-icon-plus"></i></el-button>
      </div>
      <s-table :table="tableSearch" ref="tableSearch" @http="tableWatch" :control="dialogSearch.row.ydzt !='0'">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="可用操作"
          width="120">
          <template slot-scope="s">
            <el-button type="danger" icon="delete" size="mini" @click="tableSearchDelete(s.row)"></el-button>
          </template>
        </el-table-column>
      </s-table>
    </s-dialog>
    <s-dialog :dialog="dialogSearchMx" :close="dialogSearchMxInit">
      <p slot="title">{{dialogAddMx.title}}库存移动明细</p>
      <s-table :table="tableSearchMx" ref="tableSearchMx" @http="tableWatch" :multiSelect="true" >
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="操作"
          width="80">
          <template slot-scope="s">
            <el-button type="info" size="mini" @click="dialogLocationOpen(s.row)">选择</el-button>
          </template>
        </el-table-column>
      </s-table>
      <el-button slot="footer" @click="dialogSearchMxSave">保存</el-button>
    </s-dialog>
  </div>
</template>

<script>
  import {AutoVue, AutoPromise} from '~/plugins/Tools';

  function __form () {
    return {
      tqrxm: { value: '', rule: [ 'vNull' ], cRemarks: '' },
      ydyy: { value: '', rule: [ 'vNull' ], cRemarks: '' },
    };
  }
  function __formLocation () {
    return {
      ydhkwid: { value: '', rule: [ 'vNull__change' ], cRemarks: '' },
    };
  }
  function __formAddEdit () {
    return {
      hpbh: { value: '', rule: [], cRemarks: '' },
      hpmc: { value: '', rule: [], cRemarks: '' },
      dwms: { value: '', rule: [], cRemarks: '' },
      hpph: { value: '', rule: [], cRemarks: '' },
      hpscrq: { value: '', rule: [], cRemarks: '' },
      show_kwid: { value: '', rule: [], cRemarks: '' },
      ydhkwid: { value: '', rule: [ 'vNull__change' ], cRemarks: '' },
      show_ydhkwid: { value: '', rule: [], cRemarks: '' },
      zysl: { value: '', rule: [], cRemarks: '' },
      kydsl: { value: '', rule: [], cRemarks: '' },
    };
  }
  export default AutoVue({
    name: 'stock_stockTransfer-FEcarWms',
    head: {
      'title': '库存转移管理',
      'meta': [
        { 'hid': 'description', 'name': 'description', 'content': '乐速科技平台 库存转移 查看库存转移信息' },
      ],
    },
    store: ['STOCKTRANSFER', 'DICTIONARY_stockTransfer', 'USER'],
    data: {
      table: {
        column:
          [ { label: '创建时间',
            prop: 'cjsj',
            minWidth: '100px',
            type: 'DateRange',
            cRemarks: '',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 6);
            },
            search: true },
          { label: '提起人',
            prop: 'tqrxm',
            minWidth: '80px',
            cRemarks: '',
            search: true },
          { label: '创建人',
            prop: 'cjry',
            minWidth: '80px',
            cRemarks: '',
            search: true },
          { label: '确认人',
            prop: 'qrry',
            minWidth: '80px',
            cRemarks: '',
            search: false },
          { label: '移动原因',
            prop: 'ydyy',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '确认时间',
            prop: 'qrsj',
            minWidth: '100px',
            cRemarks: '',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 6);
            },
            search: false },
          { label: '移动状态',
            prop: 'show_ydzt',
            minWidth: '0px',
            cRemarks: '0：未确认 1：已确认 2：作废',
            search: true } ],
        url: '/wmsstockmove/list',
        key: 'id',
        tableColumn: 7,
      },
      formDialog: __form(),
      dialog: {
        title: '新增',
        row: {},
        size: 'large',
        message: {},
      },
      tableAdd: {
        column:
          [ { label: '货品编号',
            prop: 'hpbh',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品名称',
            prop: 'hpmc',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '单位描述',
            prop: 'dwms',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '货品批次',
            prop: 'hpph',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '生产日期',
            prop: 'hpscrq',
            minWidth: '0px',
            cRemarks: '',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
            search: true },
          { label: '移动前库位',
            prop: 'show_kwid',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '可移动数量',
            prop: 'kydsl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '目标储位',
            prop: 'show_ydhkwid',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '移动数量',
            prop: 'zysl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          ],
        url: '/wmsshipmentorder/getShipmentOrder',
        key: 'id',
        tableColumn: 9,
      },
      dialogAddMx: {
        title: '新增',
        size: 'large',
      },
      tableAddMx: {
        column:
          [ { label: '货品编号',
            prop: 'hpbh',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品名称',
            prop: 'hpmc',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品批次',
            prop: 'hpph',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '生产日期',
            prop: 'hpscrq',
            minWidth: '0px',
            cRemarks: '',
            type: 'DateRange',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
            search: true },
          { label: '单位描述',
            prop: 'dwms',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '移动前库位',
            prop: 'show_kwid',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '可移动数量',
            prop: 'kydsl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '移动数量',
            prop: 'zysl',
            minWidth: '0px',
            cRemarks: '',
            elInputNumber: {
              min: 1,
              controls: [false, true],
              max: 'kydsl',
            },
            search: false },
          { label: '目标储位',
            prop: 'show_ydhkwid',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          ],
        url: '/wmsstockmove/searchKc',
        tableColumn: 9,
        key: 'hpkcid',
        muti: false,
      },
      dialogLocation: {
        title: '选择',
        wmsstockmove: [],
        row: {},
        show_ydhkwid: '',
      },
      formDialogLocation: __formLocation(),
      dialogAddEdit: {
        title: '编辑',
        row: '',
      },
      formDialogAddEdit: __formAddEdit(),
      tableSearch: {
        column:
          [ { label: '货品编号',
            prop: 'hpbh',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品名称',
            prop: 'hpmc',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '单位描述',
            prop: 'dwms',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '货品批次',
            prop: 'hpph',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '生产日期',
            prop: 'hpscrq',
            minWidth: '0px',
            cRemarks: '',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
            search: true },
          { label: '移动前库位',
            prop: 'show_kwid',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '可移动数量',
            prop: 'kydsl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '目标储位',
            prop: 'show_ydhkwid',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '移动数量',
            prop: 'zysl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          ],
        url: '/wmsstockmove/getWmsStockMoveDetail',
        key: 'id',
        tableColumn: 9,
      },
      dialogSearch: {
        title: '查看',
        size: 'large',
        option: {
          id: '',
        },
        row: {},
      },
      dialogSearchMx: {
        title: '新增',
        size: 'large',
      },
      tableSearchMx: {
        column:
          [ { label: '货品编号',
            prop: 'hpbh',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品名称',
            prop: 'hpmc',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '货品批次',
            prop: 'hpph',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '生产日期',
            prop: 'hpscrq',
            minWidth: '0px',
            cRemarks: '',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
            search: true },
          { label: '单位描述',
            prop: 'dwms',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '移动前库位',
            prop: 'show_kwid',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '可移动数量',
            prop: 'kydsl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '移动数量',
            prop: 'zysl',
            minWidth: '0px',
            cRemarks: '',
            elInputNumber: {
              min: 1,
              controls: [false, true],
              max: 'kydsl',
            },
            search: false },
          { label: '目标储位',
            prop: 'show_ydhkwid',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          ],
        url: '/wmsstockmove/searchKc',
        tableColumn: 9,
        key: 'hpkcid',
        muti: false,
      },
    },
    transition: 'slide-fade',
    methods: {
      tableExport (row) {
        let tableRef = 'table';

        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          this[tableRef].multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将导出库存转移。', '确认导出？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              let option = Object.assign({}, this['autoVue_' + tableRef]);
              await this.p({
                url: '/wmsstockmove/exportWmsStockMove',
                method: 'post',
                responseType: 'blob',
                data: {
                  ids,
                  ...option,
                },
              });
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      tableConfirm (row) {
        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this.table.multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this.table.multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将进行确认库存转移的操作', '确认库存转移？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsstockmove/saveConfirm', {
                ids,
              });
              this.tableWatch('table');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      tableDelete (row) {
        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this.table.multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this.table.multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将删除选择的数据', '确认删除？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsstockmove/delete', {
                ids,
              });
              this.tableWatch('table');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      tableEdit (row) {
        this.dialogOpen('PUT', row);
      },
      dialogInit () {
        this.formDialog = {
          ...this.formDialog,
          ...this.ObjectClone(__form()),
        };
        this.resetFields('formDialog');
        this.tableClear('tableAdd');
      },
      dialogOpen (type, row) {
        // console.log(USER.user.name);
        if (type) {
          type = type.toUpperCase();
        } else {
          return;
        }
        switch (type) {
        case 'ADD':
          this.dialog.title = '新增';
          break;
        case 'PUT':
          this.dialog.title = '编辑';
          this.formDialog = {
            ...this.formDialog,
            ...this.ObjectClone(__form(), row),
          };
          this.dialog.row = row;
          break;
        }
        this.dialog.visible = true;
      },
      dialogSave () {
        if (this.dialog.title === '新增') {
          this.VALIDATE('formDialog', async option => {
            let json = {
              list: this.tableAdd.data,
              ...option,
            };
            try {
              await this.post('/wmsstockmove/add', json);
              this.dialogInit();
              this.tableWatch('table');
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          });
        } else {
          this.VALIDATE('formDialog', async option => {
            try {
              option.id = this.dialog.row.id;
              await this.post('/wmsstockmove/baseUpdateByPrimaryKey', option);
              this.dialogInit();
              this.tableWatch('table');
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            };
          });
        };
      },
      tableAddDelete (index) {
        this.$confirm('您将删除选择的明细:', '确认删除？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(_ => {
            this.tableAdd.data.splice(index, 1);
          });
      },
      dialogAddMxInit () {
        this.tableClear('tableAddMx');
      },
      dialogAddMxOpen () {
        if (this.dialogAddMx.title === '新增') {
          this.tableAddMx.url = '/wmsstockmove/searchKc';
          this.tableWatch('tableAddMx');
        }
        this.dialogAddMx.visible = true;
      },
      dialogAddMxSave () {
        if (this.dialogAddMx.title === '新增') {
          if (this.tableAddMx.multipleSelection.length < 1) {
            this.$alert('请至少选择1条货品信息', '提示');
          } else {
            let bool = true;
            this.tableAddMx.multipleSelection.forEach(item => {
              if (item.show_ydhkwid === '') {
                bool = false;
                this.dialogAddMx.visible = true;
                return this.$alert('目标库位不能为空', '提示');
              }
            });
            if (bool) {
              this.tableAddMx.multipleSelection.forEach(item => {
                this.tableAdd.data.push(item);
                this.dialogAddMxInit();
                this.dialogAddMx.visible = false;
              });
            }
          }
        };
      },
      dialogLocationInit () {
        this.formDialogLocation = {
          ...this.formDialogLocation,
          ...this.ObjectClone(__formLocation()),
        };
        this.resetFields('formDialogLocation');
      },
      async dialogLocationOpen (row, query) {
        this.dialogLocation.row = row;
        await AutoPromise([
          async () => {
            await this.dialogRemoteKwmc('');
          },
          /*
          async () => {
            if (this.dialogLocation.wmsstockmove.length === 0) {
              this.dialogLocation.wmsstockmove = await this.post('/wmsstockmove/searchKw', {
                hpbh: row.hpbh,
                show_ydhkwid: query,
              });
            }
          },
          */
        ]);
        this.dialogLocation.visible = true;
      },
      dialogRemoteKwid (id) {
        if (this.dialogLocation.wmsstockmove) {
          this.dialogLocation.wmsstockmove.forEach(value => {
            if (value.id === id) {
              this.dialogLocation.show_ydhkwid = value.show_ydhkwid;
              console.log('show_ydhkwid:' + value.show_ydhkwid);
            }
          });
        }
      },
      async dialogRemoteKwmc (query, id) {
        this.dialogLocation.wmsstockmove = await this.post('/wmsstockmove/searchKw', {
          hpbh: this.dialogLocation.row.hpbh, show_ydhkwid: query});
      },
      dialogLocationSave () {
        this.VALIDATE('formDialogLocation', async option => {
          this.dialogLocation.row.show_ydhkwid = this.$refs.formDialogLocation_ydhkwid.selectedLabel;
          this.dialogLocation.row.ydhkwid = option.ydhkwid;
          this.dialogLocationInit();
          this.dialogLocation.visible = false;
        });
      },
      dialogAddEditInit () {},
      async dialogAddEditOpen (row) {
        this.formDialogAddEdit = {
          ...this.formDialogAddEdit,
          ...this.ObjectClone(__formAddEdit(), row),
        };
        this.dialogAddEdit.row = row;
        this.dialogAddEdit.visible = true;
      },
      dialogAddEditSave () {
        this.VALIDATE('formDialogAddEdit', option => {
          for (let index in option) {
            if (option.hasOwnProperty(index)) {
              this.dialogAddEdit.row[index] = option[index];
              this.dialogAddEdit.row.show_ydhkwid = this.$refs.formDialogAddEdit_ydhkwid.selectedLabel;
              this.dialogAddEdit.row.ydhkwid = option.ydhkwid;
            }
          }
        });
        this.dialogAddEditInit();
        this.dialogAddEdit.visible = false;
      },
      tableSearchDelete (row) {
        let step = [];
        if (row) {
          step.push(row.id);
        }
        this.$confirm('您将删除选择的数据', '确认删除？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsstockmove/bjDeleteMx', {
                'id': this.dialogSearch.row.id,
                'ids': step,
              });
              this.tableWatch('tableSearch');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      dialogSearchInit () {},
      dialogSearchOpen (row) {
        // this.tableWatch('tableSearch');
        if (this.dialogSearch.title === '查看') {
          this.tableSearch.option.id = row.id;
          this.tableSearch.url = '/wmsstockmove/getWmsStockMoveDetail';
          this.tableWatch('tableSearch');
        }
        /*
        try {
          this.tableSearch.data = await this.post('/wmsstockmove/getWmsStockMoveDetail', {
            id: row.id,
          });
          this.dialogSearch.option.id = row.id;
          console.log('id:' + row.id);
          console.log('id1:' + this.dialogSearch.option.id);
          this.tableSearch.url = '/wmsstockmove/getWmsStockMoveDetail';
          this.tableWatch('tableSearch');
        } catch (err) {
          console.log(err);
        };
        */
        this.dialogSearch.row = row;
        this.dialogSearch.visible = true;
      },
      dialogSearchMxInit () {
        this.tableClear('tableSearchMx');
      },
      dialogSearchMxOpen () {
        if (this.dialogSearchMx.title === '新增') {
          this.tableSearchMx.url = '/wmsstockmove/searchKc';
          this.tableWatch('tableSearchMx');
        }
        this.dialogSearchMx.visible = true;
      },
      async dialogSearchMxSave () {
        console.log('111:' + this.tableSearchMx.multipleSelection);
        if (this.dialogSearchMx.title === '新增') {
          if (this.tableSearchMx.multipleSelection.length < 1) {
            this.$alert('请至少选择1条货品信息', '提示');
          } else {
            let bool = true;
            this.tableSearchMx.multipleSelection.forEach(item => {
              if (item.show_ydhkwid === '') {
                bool = false;
                this.dialogSearchMx.visible = true;
                return this.$alert('目标库位不能为空', '提示');
              }
            });
            if (bool) {
              this.tableSearchMx.multipleSelection.forEach(item => {
                item.kcydid = this.dialogSearch.row.id;
              });
              let json = {
                list: this.tableSearchMx.multipleSelection,
              };
              try {
                await this.post('/wmsstockmove/bjSaveMx', json);
                this.tableSearch.url = '/wmsstockmove/getWmsStockMoveDetail';
                this.tableWatch('tableSearch');
                this.dialogSearchMxInit();
                this.dialogSearchMx.visible = false;
              } catch (err) {
                console.log(err);
              };
            }
          }
        };
      },
    },
    mounted: async function () {
      this.tableWatch('table');
      if (!this.DICTIONARY_stockTransfer) {
        await this.USE('DICTIONARY_stockTransfer');
      }
    },
  });
</script>
<style scoped lang="scss">
  .box-card {
    margin: 20px;
  }

  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }

  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
</style>

<style lang="scss">

</style>

